package com.wannengbang.storemobile.homepage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.base.BankCardInfoBean;
import com.wannengbang.storemobile.bean.BankInfoBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class BankAuthListAdapter extends RecyclerView.Adapter<BankAuthListAdapter.ViewHolder> {


    private List<BankInfoBean.DataBean> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public BankAuthListAdapter(List<BankInfoBean.DataBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    public void setOnCallBackListener(BankAuthListAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_bank_auth_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        BankInfoBean.DataBean dataBean = listsBeans.get(position);
        if (!TextUtils.isEmpty(dataBean.getBank_name())) {
            holder.tvBankName.setText(dataBean.getBank_name());
        } else {
            if (!TextUtils.isEmpty(dataBean.getBank_card_no())) {
                //cardNum银行卡号
                BankCardInfoBean bankCardInfoBean = new BankCardInfoBean(dataBean.getBank_card_no());
                if (bankCardInfoBean != null) {
                    String cardType = bankCardInfoBean.getCardType();//银行卡类型 比如：信用卡/储蓄卡
                    String bankName = bankCardInfoBean.getBankName();//银行卡名称  比如：建设银行/招商银行
                    holder.tvBankName.setText(bankName);
                } else {
                    holder.tvBankName.setText("");
                }
            } else {
                holder.tvBankName.setText("");
            }
        }
        if (dataBean.getBank_card_no().length() > 4) {
            holder.tvBankNo.setText(dataBean.getBank_card_no().substring(dataBean.getBank_card_no().length() - 4));
        } else {
            holder.tvBankNo.setText("0000");
        }
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_bank_name)
        TextView tvBankName;
        @BindView(R.id.tv_bank_no)
        TextView tvBankNo;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int type, int position);
    }
}
